import axios from "axios";
import Nprogress from 'nprogress';
const jdRequest = axios.create({
    baseURL:"https://api.m.jd.com/api",
    params:{
        appid:"qyg-h5"
    }
});
// 请求拦截
jdRequest.interceptors.request.use(config=>{
    Nprogress.start();
    config.params.k = Date.now();
    return config;
});
// 响应拦截
jdRequest.interceptors.response.use(response=>{
    Nprogress.done();
    if(response.data.code ===200)
        return response.data;
    else if(response.data.code === 999999){
        return Promise.reject(response.data);
    }
    else{
        alert(response.data.message);
        return new Promise(()=>{});
    }
},reason=>{
    Nprogress.done();
    alert(reason);
    return new Promise(()=>{});
});
export default jdRequest;